#pragma once

#include "event_loop.h"
#include "inet_address.h"
#include <functional>

namespace uvpp
{
	using NewConnectionCallback = std::function<void (EventLoop*, TCPPtr)>;

	class TCPAcceptor
	{
	public:
		TCPAcceptor(EventLoop* loop, bool noDelay);
		virtual ~TCPAcceptor();

		int bind(InetAddress& address);
		int listen();
		void setNewConnectionCallback(NewConnectionCallback callback);

		bool isNoDelay();
		EventLoop* loop();

	private:
		void onNewConnection(TCPPtr client);

	private:
		EventLoop* _loop;
		bool _noDelay;
		bool _listened;
		uv_tcp_t _server;

		NewConnectionCallback _newConnectionCallback;
	};
}
